#!/usr/bin/python
# -*- coding: utf-8 -*-

import datetime

class Week():
	number = 0
	startDate = ""
	endDate = ""
	shortName = ""
	longName = ""

	def __init__(self, isostring):
		dps = isostring.split("-")
		print "LOG:-----------"
		print "LOG: isostring = %s-%s-%s" % (dps[0], dps[1], dps[2])
		d = datetime.date(int(dps[0]), int(dps[1]), int(dps[2]))
		(isoyear, isoweeknumber, isoday) = d.isocalendar()
		print "LOG: isoweek = %s" % isoweeknumber
		self.number = isoweeknumber
		deltaMonday = datetime.timedelta(1 - isoday)
		deltaSunday = datetime.timedelta(7 - isoday)
		print "LOG: deltaMonday = %s, deltaSunday = %s" % (deltaMonday, deltaSunday)
		startDate = d + deltaMonday
		endDate = d + deltaSunday
		self.startDate = startDate.strftime("%Y-%m-%d")
		self.endDate = endDate.strftime("%Y-%m-%d")
		print "LOG: startDate = %s, endDate = %s" % (self.startDate, self.endDate)
		self.shortName = "%s.%s" % (str(isoweeknumber).zfill(2), str(isoyear))
		print "LOG: shortName = %s" % self.shortName
		self.longName = "Неделя %s (%s - %s)" % (self.number, startDate.strftime("%d.%m.%Y"), endDate.strftime("%d.%m.%Y"))
		print "LOG: longName = %s" % self.longName
